package com.ccit.goods.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ccit.common.exception.GymException;
import com.ccit.common.exception.fileUpload.FileEmptyException;
import com.ccit.common.result.Result;
import com.ccit.common.utils.RedisUtils;
import com.ccit.common.utils.UploadUtil;
import com.ccit.goods.service.GoodsService;
import com.ccit.model.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(tags = "商品管理")
@RestController
@RequestMapping("/goods/api")
public class GoodsApiController {
    @Autowired
    GoodsService goodsService;

    @Autowired
    private RedisUtils redisUtils;



    @ApiOperation(value = "修改商品")
    @PostMapping("/updateGoods")
    public Boolean updateGoods(@RequestBody Goods goods) {
        System.out.println(goods+"-----------------------==============================");
        boolean b = goodsService.updateById(goods);
        return b;
    }

    @PostMapping("/getByName")
    public Goods getGoodsByName(@RequestBody String  name){
        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(Goods::getName,name);
        Goods goods = goodsService.getOne(wrapper);
        System.out.println(goods+"-=-=-==-==-=-=-=-=-=-=-=-=--=--=");
        if (goods==null){
            throw new GymException(202,"没有此员工");
        }
        return goods;
    }

}
